package com.todo.strategy.online.application.api.controller;

import com.todo.common.common.entity.response.BizResponse;
import com.todo.strategy.online.application.convert.StrategyConvert;
import com.todo.strategy.online.application.entity.bo.PlanSetBO;
import com.todo.strategy.online.application.service.PlanSetService;
import com.todo.strategy.online.service.api.PlanSetApi;
import com.todo.strategy.online.service.api.response.PlanSetDetailResponse;
import com.todo.strategy.online.service.api.response.PlanSetInfoResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author azhebuxing
 * @date 2025/2/27 22:14
 * @description
 */
@Slf4j
@RestController
@RequestMapping("/api/plan")
@Tag(name = "服务端-计划集合接口", description = "服务端-计划集合接口")
public class PlanSetApiController implements PlanSetApi {

    @Resource
    private PlanSetService planSetService;


    @Override
    @Operation(summary = "根据id查询计划集合详情")
    @PostMapping("/queryPlanSetDetailById")
    public BizResponse<PlanSetDetailResponse> queryPlanSetDetailById(@RequestBody Long planId) {
        if (planId == null || planId < 0) {
            return BizResponse.paramError();
        }
        PlanSetBO planSetBO = planSetService.queryPlanSetById(planId);
        return BizResponse.success(StrategyConvert.convertToPlanSetDetailResponse(planSetBO));
    }

    @Override
    @Operation(summary = "根据id查询计划集合信息")
    @PostMapping("/queryPlanSetInfoById")
    public BizResponse<PlanSetInfoResponse> queryPlanSetInfoById(@RequestBody Long planId) {
        if (planId == null || planId < 0) {
            return BizResponse.paramError();
        }
        PlanSetBO planSetBO = planSetService.queryPlanSetById(planId);
        return BizResponse.success(StrategyConvert.convertToPlanSetInfoResponse(planSetBO));
    }

    @Override
    @Operation(summary = "根据id列表查询计划集合信息")
    @PostMapping("/queryPlanSetInfoListByIdList")
    public BizResponse<List<PlanSetInfoResponse>> queryPlanSetInfoListByIdList(@RequestBody List<Long> planIdList) {
        if (CollectionUtils.isEmpty(planIdList)){
            return BizResponse.success();
        }
        List<PlanSetBO> planSetBOS = planSetService.queryPlanSetByIdList(planIdList);
        if (CollectionUtils.isEmpty(planSetBOS)){
            return BizResponse.success();
        }
        return BizResponse.success(StrategyConvert.convertToPlanSetInfoResponseList(planSetBOS));
    }
}
